<?php
	include("HTML_top.php");
	include("header.php");
?>

<h2>PushPin Search results</h2>

<?php

include("conn.php");
connectToDB();

$s = addslashes($_GET['q']);

$q = mysql_query("
SELECT DISTINCT description, pushpin.email, pushpin.title, pushpin.url, name
FROM pushpin
INNER JOIN corkboard ON pushpin.email=corkboard.email AND pushpin.title=corkboard.title
INNER JOIN pushpin_tags ON pushpin.email=pushpin_tags.email AND pushpin.title=pushpin_tags.title AND pushpin.url=pushpin_tags.url
INNER JOIN user ON pushpin.email=user.email
WHERE private = 0 AND
(
`description`='".$s."' OR
`description` LIKE '".$s." %' OR
`description` LIKE '% ".$s." %' OR
`description` LIKE '% ".$s."' OR

`tag`='".$s."' OR
`tag` LIKE '".$s." %' OR
`tag` LIKE '% ".$s." %' OR
`tag` LIKE '% ".$s."' OR

`category`='".$s."' OR
`category` LIKE '".$s." %' OR
`category` LIKE '% ".$s." %' OR
`category` LIKE '% ".$s."'
) ORDER BY description
");

echo '<table border="0" cellspacing="0" cellpadding="10">';
echo '<tr><td width="400"><b>PushPin description</b></td><td width="200"><b>CorkBoard</b></td><td width="100"><b>Owner</b></td></tr>';

while ($r = mysql_fetch_array($q))
{
	echo '<tr>';
	
	echo '<td>';
	echo '<a href="pushpin.php?email='.urlencode($r['email']).'&title='.urlencode($r['title']).'&url='.urlencode($r['url']).'">'.$r['description'].'</a>';
	echo '</td>';
	
	echo '<td>';
	echo $r['title'];
	echo '</td>';
	
	echo '<td>';
	echo $r['name'];
	echo '</td>';
	
	echo '</tr>';
}

echo '</table>';

?>

<?php
	include("footer.php");
	include("HTML_bottom.php");
?>
